package ch03.singlcton;

/**
 * @auth 邝志豪
 * @date 2024/1/6 9:29
 */

import ch03.entity.News;
import org.apache.log4j.Logger;

/**
 * 新闻模块的DAO接口
 */
public interface NewsDao {
    /**
     * 保存新闻信息的方法
     */
    public void save(News news);
    public static NewsDao getInstance(String key){
        switch (key){
            case "mysql":
                return new NewsDaoMySqlImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "redis":
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库类型："+key+" ,DAO获取失败");
        }
    }
}
/**
 * 新闻模块的DAO实现类
 */
class NewsDaoImpl implements NewsDao{
    private Logger logger = Logger.getLogger(NewsDaoImpl.class);
    public void save(News news){
        logger.debug("保存新闻信息到数据库");
        logger.debug(news);
    }
}
interface NewsService{
    void addNews(News news);
}
